package main

import (
	"fmt"
	"math/rand"
	"sort"
	"time"
)

func delDuplicate(arr []int) (ret []int) {
	length := len(arr)
	for i := 0; i < length-1; i++ {
		for j := i + 1; j < length; j++ {
			if arr[i] == arr[j] && arr[i] != -1 {
				arr[j] = -1
			}
		}
		if arr[i] != -1 {
			ret = append(ret, arr[i])
		}
	}
	return
}

func minus(arr1, arr2 []int) (ret []int) {
	arr1len := len(arr1)
	arr2len := len(arr2)
	i := 0
	j := 0

	for i < arr1len {
		for j < arr2len {
			if arr1[i] == arr2[j] {
				if j != arr2len-1 {
					j++
				}
				break
			} else if arr1[i] < arr2[j] {
				ret = append(ret, arr1[i])
				break
			} else {
				if j == arr2len-1 {
					for _, v := range arr1[i:] {
						ret = append(ret, v)
					}
				}
				j++
			}
		}
		i++
	}
	return
}

func main() {
	L1 := make([]int, 50)
	L2 := make([]int, 50)
	rand.Seed(time.Now().UnixNano())

	length := len(L1)
	for i := 0; i < length; i++ {
		L1[i] = rand.Intn(100)
		L2[i] = rand.Intn(100)
	}

	L1 = delDuplicate(L1)
	L2 = delDuplicate(L2)
	sort.Ints(L1)
	sort.Ints(L2)

	fmt.Println("L1:", L1)
	fmt.Println("L2:", L2)

	fmt.Println()
	fmt.Println("L1-l2:", minus(L1, L2))
}
